// pages/edit8/edit8.js
Page({

  data: {
         files:[],goods_id:'',near_id:''
  },

 
  onLoad: function (options) {
    if(options.goods_id){
      this.setData({
        goods_id:options.goods_id,
        near_id:options.near_id
      })
    }
  },

  
  onShow: function () {

  },
   getchooseall(){
     let files=this.data.files
     console.log(files);
     
      wx.chooseImage({
        count: 9,
        success:(res)=>{
          console.log(res);
          console.log(files.concat(res.tempFiles));
          
        let file=  files.concat(res.tempFiles)
        this.setData({files:file})
          
          
        }
      })
   },
   shanchu(e){
    let files=this.data.files
    files.splice(e.currentTarget.dataset.i,1)
    this.setData({
      files,
      
    })
 },
 bianji(e){
  wx.navigateTo({
    url: '/pages/edit5/edit5?url='+this.data.files[e.currentTarget.dataset.i].path+'&flag=14'+'&index3='+e.currentTarget.dataset.i,
  })
},
//多图转pdf
upload1(){
  if(this.data.files.length==0){
    wx.showToast({
      title: '请上传图片',
      icon:'none'
    })
    return
  }
  wx.showLoading({
    title: '正在上传...',
    mask:true
  })
   this.getpdfarr()
          // array.push(item.path)
          // if(array.length==this.data.files.length){
          //   this.getpdfimage(array)
          // }
  
     
},
getpdfimage(file){
  wx.request({
    url: 'https://zujieba.com/Api/upload/selectionSplicingToNewPdf.html',
    data:{pdf_road_datas:file},
    method:'POST',
    success:(res)=>{
      console.log(res);
      
      let url="https://zujieba.com/"+res.data.data
      //将图片转为pdf后需要变为临时路径预览
     wx.downloadFile({
       url: url,
       success:(res1)=>{
         console.log(res1);
       
         if(res.data.success==1){
           wx.hideLoading()
          //  wx.navigateTo({
          //    url: '/pages/fileprint/print/print?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&filepath="+url+"&name="+res.data.data+
          //    '&time='+res.data.addtime+'&page='+res.data.page+"&url="+url+'&radio5=4'
          //  })
          wx.navigateTo({
            url: '/pages/fileprint/print/newprint?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&filepath="+url+"&name="+res.data.data+
            '&time='+res.data.addtime+'&page='+res.data.page+"&url="+url+'&radio5=4'
          })
         
         }else{
           wx.showToast({
             title: res.data.tips,
             icon:'none'
           })
         }
         
       }
     })
    
     
      
    },
    fail:(res)=>{
      console.log(res);
      
    }
  })

},
  // 将多图分别上传 
   getpdfarr(){
    let array=[]
    this.data.files.forEach((item)=>{
      wx.uploadFile({
        filePath: item.path,
        name: 'file',
        url: 'https://zujieba.com/Api/upload/upload',
        success:(res)=>{
          console.log(res);
          let res1=JSON.parse(res.data)
          array.push(res1.name)
          this.setData({
            array
          })
          if(array.length==this.data.files.length){
            console.log(array);
            
            this.getpdfimage(array)
          }
        }
      })
    })
   
   }
})